#include <stdafx.h>
#include "LitEditorMouse.h"

namespace Lit
{
	namespace Editor
	{
		DragInfos::DragInfos() : mDrag(false){}
		DragInfos::~DragInfos(){}

		bool DragInfos::hasButton( Qt::MouseButton btn ) const{ return mButtons&btn; }
		const Qt::MouseButtons& DragInfos::getButtons() const{ return mButtons; }

		const Vec2 &DragInfos::getStart() const{ return mStart; }
		const Vec2 &DragInfos::getEnd() const{ return mEnd; }
		
		Vec2 DragInfos::start( Qt::MouseButtons btns ) { mButtons=btns; QPoint p(QCursor::pos()); mStart = mEnd = Vec2(p.x(), p.y()); mDrag = true; return mStart; }

		// single step function
		// e.g inside loops etc
		//! returns: current delta
		Vec2 DragInfos::step() { if( !mDrag ) return Vec2::ZERO; mStart = mEnd; QPoint p(QCursor::pos()); mEnd = Vec2(p.x(), p.y());return getDelta(); }
		Vec2 DragInfos::stop() { QPoint p(QCursor::pos()); mEnd = Vec2(p.x(), p.y()); mDrag = false; return mEnd; }
		bool DragInfos::isDragging() const{ return mDrag; }

		Vec2 DragInfos::getDelta( Real factor ) const{ return (mEnd - mStart)*factor; }
		QRect DragInfos::getGeometry() const{ Vec2 d(getDelta()); return QRect( mStart.x, mStart.y, d.x, d.y ); }
	};
};